package vip.xiaonuo.smzq.modular.dictionary.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.smzq.modular.dictionary.entity.Cb01Zh;
import vip.xiaonuo.smzq.modular.dictionary.entity.Cb05Kclx;
import vip.xiaonuo.smzq.modular.dictionary.entity.vo.Cb01ZhVo;
import vip.xiaonuo.smzq.modular.dictionary.entity.vo.DictionaryBean;
import vip.xiaonuo.smzq.modular.dictionary.mapper.Cb01ZhMapper;
import vip.xiaonuo.smzq.modular.dictionary.mapper.Cb05KclxMapper;
import vip.xiaonuo.smzq.modular.dictionary.mapper.Cb09HkcwMapper;
import vip.xiaonuo.smzq.modular.dictionary.service.ICb01ZhService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 字典表1综合 服务实现类
 *
 * @author eomer
 * @since 2024-02-21
 */
@Service
public class Cb01ZhServiceImpl extends ServiceImpl<Cb01ZhMapper, Cb01Zh> implements ICb01ZhService {

    @Resource
    private Cb01ZhMapper cb01ZhMapper;
    @Resource
    private Cb05KclxMapper cb05KclxMapper;//矿床类型

    @Resource
    private Cb09HkcwMapper cb09HkcwMapper;//含矿层位

    @Override
    public Page<Cb01Zh> page(Cb01Zh cb01Zh) {
        QueryWrapper<Cb01Zh> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Override
    public void excelImport(MultipartFile file) {

    }
    /**
     * 矿产组合下拉框
     */
    @Override
    public List<Cb01Zh> mineralsZh() {
        QueryWrapper<Cb01Zh> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bh",16);
        queryWrapper.ne("bnm",0);
        return cb01ZhMapper.selectList(queryWrapper);
    }

    /**
     * 矿产字典查询
     */
    @Override
    public DictionaryBean getDictionaryBean() {
        DictionaryBean dictionaryBean=new DictionaryBean();
        //企业类型
        QueryWrapper<Cb01Zh> enterpriseType = new QueryWrapper<>();
        enterpriseType.eq("bh",46);
        enterpriseType.ne("bnm",0);
        List<Cb01Zh> enterpriseTypes=cb01ZhMapper.selectList(enterpriseType);
        dictionaryBean.setEnterpriseTypes(enterpriseTypes);
        //生产状态
        QueryWrapper<Cb01Zh> productionStatu = new QueryWrapper<>();
        productionStatu.eq("bh",47);
        productionStatu.ne("bnm",0);
        List<Cb01Zh> productionStatus=cb01ZhMapper.selectList(productionStatu);
        dictionaryBean.setProductionStatus(productionStatus);
        //矿山规模
        QueryWrapper<Cb01Zh> mineScale = new QueryWrapper<>();
        mineScale.eq("bh",49);
        mineScale.ne("bnm",0);
        List<Cb01Zh> mineScales=cb01ZhMapper.selectList(mineScale);
        dictionaryBean.setMineScales(mineScales);
        //计量单位和矿产质量指标单位
        QueryWrapper<Cb01Zh> mineQualityUnit = new QueryWrapper<>();
        mineQualityUnit.eq("bh",29);
        mineQualityUnit.ne("bnm",0);
        List<Cb01Zh> mineQualityUnits=cb01ZhMapper.selectList(mineQualityUnit);
        dictionaryBean.setMineQualityUnits(mineQualityUnits);
        //开采方式
        QueryWrapper<Cb01Zh> mineOpenMethod = new QueryWrapper<>();
        mineOpenMethod.eq("bh",26);
        mineOpenMethod.ne("bnm",0);
        List<Cb01Zh> mineOpenMethods=cb01ZhMapper.selectList(mineOpenMethod);
        dictionaryBean.setMineOpenMethods(mineOpenMethods);
        //开拓方式
        QueryWrapper<Cb01Zh> exploitationMode = new QueryWrapper<>();
        exploitationMode.eq("bh",45);
        exploitationMode.ne("bnm",0);
        List<Cb01Zh> exploitationModeS=cb01ZhMapper.selectList(exploitationMode);
        dictionaryBean.setExploitationModeS(exploitationModeS);
        //采矿方式
        QueryWrapper<Cb01Zh> miningMode = new QueryWrapper<>();
        miningMode.eq("bh",44);
        miningMode.ne("bnm",0);
        List<Cb01Zh> miningModes=cb01ZhMapper.selectList(miningMode);
        dictionaryBean.setMiningModes(miningModes);
        //选矿方式
        QueryWrapper<Cb01Zh> miningMethod = new QueryWrapper<>();
        miningMethod.eq("bh",48);
        miningMethod.ne("bnm",0);
        List<Cb01Zh> miningMethods=cb01ZhMapper.selectList(miningMethod);
        dictionaryBean.setMiningMethods(miningMethods);
        //选矿难易程度
        QueryWrapper<Cb01Zh> miningDifficulty = new QueryWrapper<>();
        miningDifficulty.eq("bh",20);
        miningDifficulty.ne("bnm",0);
        List<Cb01Zh> miningDifficultys=cb01ZhMapper.selectList(miningDifficulty);
        dictionaryBean.setMiningDifficultys(miningDifficultys);
        //选矿实验程度
        QueryWrapper<Cb01Zh> miningExperiment = new QueryWrapper<>();
        miningExperiment.eq("bh",27);
        miningExperiment.ne("bnm",0);
        List<Cb01Zh> miningExperiments=cb01ZhMapper.selectList(miningExperiment);
        dictionaryBean.setMiningExperiments(miningExperiments);
        //回收类别
        QueryWrapper<Cb01Zh> recyclingCategorie = new QueryWrapper<>();
        recyclingCategorie.eq("bh",18);
        recyclingCategorie.ne("bnm",0);
        List<Cb01Zh> recyclingCategories=cb01ZhMapper.selectList(recyclingCategorie);
        dictionaryBean.setRecyclingCategories(recyclingCategories);
        //矿床类型
        dictionaryBean.setDepositTypes(cb05KclxMapper.selectList(new QueryWrapper<>()));
        //含矿层位
        dictionaryBean.setDepositLayers(cb09HkcwMapper.selectList(new QueryWrapper<>()));
        //构造复杂程度
        QueryWrapper<Cb01Zh> constructionComplexitie = new QueryWrapper<>();
        constructionComplexitie.eq("bh",31);
        constructionComplexitie.ne("bnm",0);
        List<Cb01Zh> constructionComplexities=cb01ZhMapper.selectList(constructionComplexitie);
        dictionaryBean.setConstructionComplexities(constructionComplexities);
        //煤层稳定程度
        QueryWrapper<Cb01Zh> coalStability = new QueryWrapper<>();
        coalStability.eq("bh",32);
        coalStability.ne("bnm",0);
        List<Cb01Zh> coalStabilitys=cb01ZhMapper.selectList(coalStability);
        dictionaryBean.setCoalStability(coalStabilitys);
        //沼气等级
        QueryWrapper<Cb01Zh> swampLevel = new QueryWrapper<>();
        swampLevel.eq("bh",33);
        swampLevel.ne("bnm",0);
        List<Cb01Zh> swampLevels=cb01ZhMapper.selectList(swampLevel);
        dictionaryBean.setSwampLevels(swampLevels);
        //煤尘
        QueryWrapper<Cb01Zh> coalDust = new QueryWrapper<>();
        coalDust.eq("bh",34);
        coalDust.ne("bnm",0);
        List<Cb01Zh> coalDusts=cb01ZhMapper.selectList(coalDust);
        dictionaryBean.setCoalDusts(coalDusts);
        //矿区远景评价
        QueryWrapper<Cb01Zh> futureEvaluation = new QueryWrapper<>();
        futureEvaluation.eq("bh",35);
        futureEvaluation.ne("bnm",0);
        List<Cb01Zh> futureEvaluations=cb01ZhMapper.selectList(futureEvaluation);
        dictionaryBean.setFutureEvaluations(futureEvaluations);
        //储量规模
        QueryWrapper<Cb01Zh> reserveScale = new QueryWrapper<>();
        reserveScale.eq("bh",13);
        reserveScale.ne("bnm",0);
        List<Cb01Zh> reserveScales=cb01ZhMapper.selectList(reserveScale);
        dictionaryBean.setReserveScales(reserveScales);
        //矿体形态
        QueryWrapper<Cb01Zh> mineralForm = new QueryWrapper<>();
        mineralForm.eq("bh",13);
        mineralForm.ne("bnm",0);
        List<Cb01Zh> mineralForms=cb01ZhMapper.selectList(mineralForm);
        dictionaryBean.setMineralForms(mineralForms);
        //提交评审原因
        QueryWrapper<Cb01Zh> submitReviewReason = new QueryWrapper<>();
        submitReviewReason.eq("bh",30);
        submitReviewReason.ne("bnm",0);
        List<Cb01Zh> submitReviewReasons=cb01ZhMapper.selectList(submitReviewReason);
        dictionaryBean.setSubmitReviewReasons(submitReviewReasons);
        //勘察阶段
        QueryWrapper<Cb01Zh> explorationStage = new QueryWrapper<>();
        explorationStage.eq("bh",15);
        explorationStage.ne("bnm",0);
        explorationStage.in("bnm",101,102,103);
        List<Cb01Zh> explorationStages=cb01ZhMapper.selectList(explorationStage);
        dictionaryBean.setExplorationStages(explorationStages);
        //利用情况
        QueryWrapper<Cb01Zh> utilizationStatuse = new QueryWrapper<>();
        utilizationStatuse.eq("bh",12);
        utilizationStatuse.ne("bnm",0);
        List<Cb01Zh> utilizationStatuses=cb01ZhMapper.selectList(utilizationStatuse);
        dictionaryBean.setUtilizationStatuses(utilizationStatuses);
        //评价阶段
        QueryWrapper<Cb01Zh> evaluationStage = new QueryWrapper<>();
        evaluationStage.eq("bh",50);
        evaluationStage.ne("bnm",0);
        List<Cb01Zh> evaluationStages=cb01ZhMapper.selectList(evaluationStage);
        dictionaryBean.setEvaluationStages(evaluationStages);
        //建设项目类别
        QueryWrapper<Cb01Zh> constructionProjectCategorie = new QueryWrapper<>();
        constructionProjectCategorie.eq("bh",42);
        constructionProjectCategorie.ne("bnm",0);
        List<Cb01Zh> constructionProjectCategories=cb01ZhMapper.selectList(constructionProjectCategorie);
        dictionaryBean.setConstructionProjectCategories(constructionProjectCategories);
        //建设项目类别
        QueryWrapper<Cb01Zh> pressureWearingPropertie = new QueryWrapper<>();
        pressureWearingPropertie.eq("bh",55);
        pressureWearingPropertie.ne("bnm",0);
        List<Cb01Zh> pressureWearingProperties=cb01ZhMapper.selectList(pressureWearingPropertie);
        dictionaryBean.setPressureWearingProperties(pressureWearingProperties);
        //资料类型
        QueryWrapper<Cb01Zh> dataType = new QueryWrapper<>();
        dataType.eq("bh",300);
        dataType.ne("bnm",0);
        List<Cb01Zh> dataTypes=cb01ZhMapper.selectList(dataType);
        dictionaryBean.setDataTypes(dataTypes);
        //矿业权库类型
        QueryWrapper<Cb01Zh> miningRightLibrarie = new QueryWrapper<>();
        miningRightLibrarie.eq("bh",301);
        miningRightLibrarie.ne("bnm",0);
        List<Cb01Zh> miningRightLibraries=cb01ZhMapper.selectList(miningRightLibrarie);
        dictionaryBean.setMiningRightLibraries(miningRightLibraries);
        //矿业权登记类型
        QueryWrapper<Cb01Zh> miningRightRegistration = new QueryWrapper<>();
        miningRightRegistration.eq("bh",302);
        miningRightRegistration.ne("bnm",0);
        List<Cb01Zh> miningRightRegistrations=cb01ZhMapper.selectList(miningRightRegistration);
        dictionaryBean.setMiningRightRegistrations(miningRightRegistrations);
        //节点类型
        QueryWrapper<Cb01Zh> nodeType = new QueryWrapper<>();
        nodeType.eq("bh",303);
        nodeType.ne("bnm",0);
        List<Cb01Zh> nodeTypes=cb01ZhMapper.selectList(nodeType);
        dictionaryBean.setNodeTypes(nodeTypes);
        //知识库文件类型
        QueryWrapper<Cb01Zh> knowledgeBaseFileType = new QueryWrapper<>();
        knowledgeBaseFileType.eq("bh",304);
        knowledgeBaseFileType.ne("bnm",0);
        List<Cb01Zh> knowledgeBaseFileTypes=cb01ZhMapper.selectList(knowledgeBaseFileType);
        dictionaryBean.setKnowledgeBaseFileTypes(knowledgeBaseFileTypes);
        //知识库文件类型
        QueryWrapper<Cb01Zh> changeType = new QueryWrapper<>();
        changeType.eq("bh",305);
        changeType.ne("bnm",0);
        List<Cb01Zh> changeTypes=cb01ZhMapper.selectList(changeType);
        dictionaryBean.setChangeTypes(changeTypes);
        //驾驶舱消息类型
        QueryWrapper<Cb01Zh> jscxxlbn = new QueryWrapper<>();
        jscxxlbn.eq("bh",306);
        jscxxlbn.ne("bnm",0);
        List<Cb01Zh> jscxxlbns=cb01ZhMapper.selectList(jscxxlbn);
        dictionaryBean.setJscxxlb(jscxxlbns);
        //驾驶舱消息类型
        QueryWrapper<Cb01Zh> yjlx = new QueryWrapper<>();
        yjlx.eq("bh",308);
        yjlx.ne("bnm",0);
        List<Cb01Zh> yjlxList=cb01ZhMapper.selectList(yjlx);
        dictionaryBean.setYjlxList(yjlxList);

        //上表标识
        QueryWrapper<Cb01Zh> sbbs = new QueryWrapper<>();
        sbbs.eq("bh",71);
        sbbs.ne("bnm",0);
        List<Cb01Zh> sbbss=cb01ZhMapper.selectList(sbbs);
        dictionaryBean.setSbbsList(sbbss);

        //生产状态
        QueryWrapper<Cb01Zh> sczt = new QueryWrapper<>();
        sczt.eq("bh",47);
        sczt.ne("bnm",0);
        List<Cb01Zh> scztList=cb01ZhMapper.selectList(sczt);
        dictionaryBean.setScztList(scztList);

        //矿山规模
        QueryWrapper<Cb01Zh> ksgm = new QueryWrapper<>();
        ksgm.eq("bh",49);
        ksgm.ne("bnm",0);
        List<Cb01Zh> ksgms=cb01ZhMapper.selectList(ksgm);
        dictionaryBean.setKsgmList(ksgms);

        //评审备案-报告类型
        QueryWrapper<Cb01Zh> psbaBglx = new QueryWrapper<>();
        psbaBglx.eq("bh",309);
        psbaBglx.ne("bnm",0);
        List<Cb01Zh> psbaBglxList=cb01ZhMapper.selectList(psbaBglx);
        dictionaryBean.setPsbaBglxList(psbaBglxList);





        return dictionaryBean;
    }

    /**
     * 矿产字典查询-重构
     *
     * @author Kevin
     * @since 2024/7/22 17:40
     */
    @Override
    public DictionaryBean getKcDictionary() {

        DictionaryBean dictionaryBean = new DictionaryBean();

        //矿床类型
        dictionaryBean.setDepositTypes(cb05KclxMapper.selectList(new QueryWrapper<>()));
        //含矿层位
        dictionaryBean.setDepositLayers(cb09HkcwMapper.selectList(new QueryWrapper<>()));

        List<Cb01ZhVo> list = cb01ZhMapper.getKcDictionaryList();

        //根据type字段分组
        Map<String, List<Cb01ZhVo>> groupMap = list.stream().collect(Collectors.groupingBy(Cb01ZhVo::getType));
        //遍历分组
        groupMap.forEach((key, value) -> {

            List<Cb01Zh> valueList = value.stream()
                    .map(item -> new Cb01Zh() {{
                        setPkid(item.getPkid());
                        setBh(item.getBh());
                        setBnm(item.getBnm());
                        setDm(item.getDm());
                        setMc(item.getMc());
                    }}).collect(Collectors.toList());

            switch (key) {
                case "企业类型":
                    dictionaryBean.setEnterpriseTypes(valueList);
                    break;
                case "生产状态":
                    dictionaryBean.setProductionStatus(valueList);
                    dictionaryBean.setScztList(valueList);
                    break;
                case "矿山规模":
                    dictionaryBean.setMineScales(valueList);
                    dictionaryBean.setKsgmList(valueList);
                    break;
                case "计量单位和矿产质量指标单位":
                    dictionaryBean.setMineQualityUnits(valueList);
                    break;
                case "开采方式":
                    dictionaryBean.setMineOpenMethods(valueList);
                    break;
                case "开拓方式":
                    dictionaryBean.setExploitationModeS(valueList);
                    break;
                case "采矿方式":
                    dictionaryBean.setMiningModes(valueList);
                    break;
                case "选矿方式":
                    dictionaryBean.setMiningMethods(valueList);
                    break;
                case "选矿难易程度":
                    dictionaryBean.setMiningDifficultys(valueList);
                    break;
                case "选矿实验程度":
                    dictionaryBean.setMiningExperiments(valueList);
                    break;
                case "回收类别":
                    dictionaryBean.setRecyclingCategories(valueList);
                    break;
                case "构造复杂程度":
                    dictionaryBean.setConstructionComplexities(valueList);
                    break;
                case "煤层稳定程度":
                    dictionaryBean.setCoalStability(valueList);
                    break;
                case "沼气等级":
                    dictionaryBean.setSwampLevels(valueList);
                    break;
                case "煤尘":
                    dictionaryBean.setCoalDusts(valueList);
                    break;
                case "矿区远景评价":
                    dictionaryBean.setFutureEvaluations(valueList);
                    break;
                case "储量规模":
                    dictionaryBean.setReserveScales(valueList);
                    break;
                case "矿体形态":
                    dictionaryBean.setMineralForms(valueList);
                    break;
                case "提交评审原因":
                    dictionaryBean.setSubmitReviewReasons(valueList);
                    break;
                case "勘察阶段":
                    dictionaryBean.setExplorationStages(valueList);
                    break;
                case "利用情况":
                    dictionaryBean.setUtilizationStatuses(valueList);
                    break;
                case "评价阶段":
                    dictionaryBean.setEvaluationStages(valueList);
                    break;
                case "建设项目类别":
                    dictionaryBean.setConstructionProjectCategories(valueList);
                    break;
                case "压覆性质":
                    dictionaryBean.setPressureWearingProperties(valueList);
                    break;
                case "资料类型":
                    dictionaryBean.setDataTypes(valueList);
                    break;
                case "矿业权库类型":
                    dictionaryBean.setMiningRightLibraries(valueList);
                    break;
                case "矿业权登记类型":
                    dictionaryBean.setMiningRightRegistrations(valueList);
                    break;
                case "节点类型":
                    dictionaryBean.setNodeTypes(valueList);
                    break;
                case "知识库文件类型":
                    dictionaryBean.setKnowledgeBaseFileTypes(valueList);
                    break;
                case "变更类型":
                    dictionaryBean.setChangeTypes(valueList);
                    break;
                case "驾驶舱消息类型":
                    dictionaryBean.setJscxxlb(valueList);
                    break;
                case "预警类型":
                    dictionaryBean.setYjlxList(valueList);
                    break;
                case "上表标识":
                    dictionaryBean.setSbbsList(valueList);
                    break;
                case "评审备案-报告类型":
                    dictionaryBean.setPsbaBglxList(valueList);
                    break;
                case "矿产大类不包括建材子类":
                    dictionaryBean.setKcdlbList(valueList);
                    break;
                default:
                    break;
            }
        });

        return dictionaryBean;
    }
}
